﻿using System;
using System.Collections.Generic;
using System.Linq;

using System.Web.Mvc;
using Prodma.DataAccess.Database;
using Prodma.DataAccess.Models;
using Prodma.DataAccess.Helper.Enumerators;
using Prodma.DataAccess.Models.ViewModels;

namespace Prodma.DataAccess.DataService.ListService
{
    public static class MenuLocationList
    {

        private static DataContext context = new DataContext();

        public static SelectList GetList()
        {
            int stateId = Convert.ToInt32(State.Active);
            DataContext context = new DataContext();
            using (context)
            {
                var list = (from location in context.tb_MenuLocation
                            where location.tb_State.Id == stateId
                            select location);

                SelectList selectList = new SelectList(list.ToDictionary(x => x.Id, z => z.Name), "Key", "Value");

                return selectList;
            }
        }
        public static SelectList GetList(int id)
        {
            int stateId = Convert.ToInt32(State.Active);
            DataContext context = new DataContext();
            using (context)
            {
                var list = (from location in context.tb_MenuLocation
                            where location.tb_State.Id == stateId
                            select location);

                SelectList selectList = new SelectList(list.ToDictionary(x => x.Id, z => z.Name), "Key", "Value", id);

                return selectList;
            }
        }
        public static IList<MenuLocationVm> GetMenuLocationListForAdminMenu()
        {
            DataContext context = new DataContext();
            using (context)
            {
                var list = (from location in context.tb_MenuLocation
                            select new MenuLocationVm()
                            {
                                Id = location.Id,
                                Name = location.Name
                            }).ToList();

                return list;
            }
        }
    }
}
